package windbell.domain.risk.impl;

import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Date;
import org.hibernate.Query;
import windbell.domain.risk.RiskCheckSource;
import windbell.domain.risk.RiskCheckSourceCriteria;
import windbell.domain.risk.RiskCheckSourceType;

public class RiskCheckSourceCriteriaImpl extends HQLBasedPagedQueryCriteria<RiskCheckSource> implements RiskCheckSourceCriteria {
  private RiskCheckSourceType type;
  
  public RiskCheckSourceType getType() {
    return this.type;
  }
  
  public RiskCheckSourceCriteria setType(final RiskCheckSourceType type) {
    this.type = type;
    return this;			
    
  }
  
  private Date dateFrom;
  
  public Date getDateFrom() {
    return this.dateFrom;
  }
  
  public RiskCheckSourceCriteria setDateFrom(final Date dateFrom) {
    this.dateFrom = dateFrom;
    return this;			
    
  }
  
  private Date dateTo;
  
  public Date getDateTo() {
    return this.dateTo;
  }
  
  public RiskCheckSourceCriteria setDateTo(final Date dateTo) {
    this.dateTo = dateTo;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from windbell.domain.risk.impl.RiskCheckSourceImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getType()) ){
    	hql += " and ((this.type) = (:type))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateFrom()) ){
    	hql += " and ((this.date) >= (:dateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateTo()) ){
    	hql += " and ((this.date) <= (:dateTo))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getType())){
    	query.setParameter("type",getType()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateFrom())){
    	query.setParameter("dateFrom",getDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateTo())){
    	query.setParameter("dateTo",getDateTo()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RiskCheckSourceCriteriaImpl() {
    initOrderBys();
  }
}
